package utils

import (
	"blog/errmsg"
	"github.com/gin-gonic/gin"
)

/**
http响应函数封装
 */
func HttpResponse(c *gin.Context,httpstatus,code int,msg string,data interface{}){
	if code!= errmsg.SUCCESS && AppMode == "debug"{
		msg = errmsg.GetCodeMsg(code) + " " + msg
	}else {
		msg = errmsg.GetCodeMsg(code)
	}
	if data == nil{
		data = gin.H{}
	}
	c.JSON(httpstatus,gin.H{
		"code": code,
		"msg":  msg,
		"data": data,
	})
}
func HttpResponseTotal(c *gin.Context,httpstatus,code int,msg string,data interface{},total int){
	if code!= errmsg.SUCCESS && AppMode == "debug"{
		msg = errmsg.GetCodeMsg(code) + " " + msg
	}else {
		msg = errmsg.GetCodeMsg(code)
	}
	if data == nil{
		data = gin.H{}
	}
	c.JSON(httpstatus,gin.H{
		"code": code,
		"msg":  msg,
		"data": data,
		"total":total,
	})
}
